package com.llb666.e.shop.api.dto;

import com.llb666.e.shop.domain.entity.Users;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

import javax.validation.constraints.Email;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.util.Date;

/**
 * 用户中心dto.
 *
 * @author llb666
 */
@Data
@Schema(name = "用户对象", description = "从客户端，由用户传入的数据封装在此entity中")
public class CenterUserDto {

    @Schema(description = "用户名", name = "username", example = "json")
    private String username;

    @Schema(description = "密码", name = "password", example = "123456")
    private String password;

    @Schema(description = "确认密码", name = "confirmPassword", example = "123456")
    private String confirmPassword;

    @NotBlank(message = "用户昵称不能为空")
    @Length(max = 12, message = "用户昵称不能超过12位")
    @Schema(description = "昵称", name = "nickname", example = "杰森")
    private String nickname;

    @Length(max = 12, message = "用户真实姓名不能超过12位")
    @Schema(description = "真实姓名", name = "realname", example = "杰森")
    private String realname;

    @Pattern(regexp = "^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\\d{8})$", message = "手机号格式不正确")
    @Schema(description = "手机号", name = "mobile", example = "13999999999")
    private String mobile;

    @Email
    @Schema(description = "邮箱地址", name = "email", example = "ailbin@qq.com")
    private String email;

    @Min(value = 0, message = "性别选择不正确")
    @Max(value = 2, message = "性别选择不正确")
    @Schema(description = "性别", name = "sex", example = "0:女 1:男 2:保密")
    private Integer sex;

    @Schema(description = "生日", name = "birthday", example = "1900-01-01")
    private Date birthday;

    @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
    public interface Converter {
        CenterUserDto.Converter INSTANCE = Mappers.getMapper(CenterUserDto.Converter.class);

        Users dto2do(CenterUserDto activity);
    }
}
